package com.pwl.shiro.text;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

public class Main {
    public static void main(String[] args) {
        String password="123456";
        //盐值
        String salt="fsafw";
        //e10adc3949ba59abbe56e057f20f883e
        //14e1b600b1fd579f47433b88e8d85291
        //加密
        //增加密码强度、在此加密
        Md5Hash md5Hash= new  Md5Hash(password,salt,2);
//        Md5Hash md5Hash1= new  Md5Hash(md5Hash.toString());
        System.out.println(md5Hash.toString());
//        System.out.println(md5Hash1.toString());

//************************************************************
//        //工厂类：负责生产SecurityManager
//        Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:shiro.ini");
//        //Shiro的核心：安全管理器
//        SecurityManager securityManager=  factory.getInstance();
//        //将完全管理器  添加到当前认证环境中
//        SecurityUtils.setSecurityManager(securityManager);
//        //认证主体： 用于保存用户输入的账号和密码
//        Subject subject=SecurityUtils.getSubject();
//        //token:令牌  存放了账号 和密码
//        String username="zhangsan";
//        String password="wanlonga";
//        UsernamePasswordToken token=new UsernamePasswordToken(username,password);
//        try {
//            subject.login(token);
//            System.out.println("认证成功");
//        } catch (AuthenticationException e) {
//            //IncorrectCredentialsException 密码错误
//            //UnknownAccountException  账号错误
//            e.printStackTrace();
//        }
    }
}
